<template>
	<view class="p-30">
		<u-form labelWidth="150rpx" labelPosition="top" :model="form" :rules="rules" ref="uForm" errorType="toast">
			<view class="card p-30">
				<u-form-item label="提现金额" prop="money" borderBottom>
					<u-input v-model="form.money" placeholder="请输入提现金额" border="none">
						<view slot="suffix">
							可提现金额 {{$userInfo.money}}
						</view>
					</u-input>
				</u-form-item>

			</view>
		</u-form>

		<view class="mt-30">
			<u-button @click="submit" type="primary" :loading="loading" text="提交"></u-button>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import {
		withdrawSubmit
	} from '@/common/api.js'
	import {
		mapState
	} from "vuex";
	import commonMixin from '@/mixins/common.js';
	export default {
		mixins: [commonMixin],
		data() {
			return {
				loading: false,
				form: {
					money: "",
				},
				rules: {
					money: {
						required: true,
						message: '请填写提现金额',
						trigger: ['blur', 'change']
					}
				}
			}
		},
		computed: {
			...mapState([]),
		},
		onReady() {
			//如果需要兼容微信小程序，并且校验规则中含有方法等，只能通过setRules方法设置规则。
			this.$refs.uForm.setRules(this.rules)
		},
		onShow() {
			this.$store.dispatch('getUserInfo');
		},
		onLoad() {},
		methods: {
			submit() {
				let vm = this;
				vm.loading = true;
				this.$refs.uForm.validate().then(res => {
					withdrawSubmit(vm.form).then(res => {
						vm.$refs.uToast.show({
							type: 'success',
							message: res.msg,
							complete() {
								vm.loading = false;
								uni.redirectTo({
									url: '/pages/mine/mine'
								})
							}
						})
					}).catch(err => {
						console.log(err);
						vm.loading = false;
					})

				}).catch(errors => {
					console.log(errors);
					vm.loading = false;
				})
			}
		},
	}
</script>

<style lang="scss" scoped>
</style>